#include "stdafx.h"
#include "log/logfactory.hpp"
#include "log/asyncchannel.hpp"
#include "log/windowsconsolechannel.hpp"
#include "log/formattingchannel.hpp"
#include "log/splitterchannel.hpp"
#include "log/eventlogchannel.hpp"
#include "designpattern/singletonholder.hpp"
using JHCPP::designpattern::TSingletonHolder;


namespace JHCPP
{
	namespace log
	{
		CLogFactory::CLogFactory()
		{
			registerBuiltins();
		}

		CLogFactory::~CLogFactory()
		{
		}

		void CLogFactory::registerChannelClass(const std::string& className, ChannelInstantiator* pFactory)
		{
			m_channelFactory.registerClass(className, pFactory);
		}

		void CLogFactory::registerFormatterClass(const std::string& className, FormatterFactory* pFactory)
		{
			m_formatterFactory.registerClass(className, pFactory);
		}

		CChannel* CLogFactory::createChannel(const std::string& className) const
		{
			return m_channelFactory.createInstance(className);
		}

		CFormatter* CLogFactory::createFormatter(const std::string& className) const
		{
			return m_formatterFactory.createInstance(className);
		}

		static TSingletonHolder<CLogFactory> sh;

		CLogFactory& CLogFactory::defaultFactory()
		{
			return *sh.get();
		}

		void CLogFactory::registerBuiltins()
		{
			
			m_channelFactory.registerClass("AsyncChannel", new TInstantiator<CAsyncChannel, CChannel>);
			m_channelFactory.registerClass("ConsoleChannel", new TInstantiator<CWindowsConsoleChannel, CChannel>);
			m_channelFactory.registerClass("ColorConsoleChannel", new TInstantiator<CWindowsColorConsoleChannel, CChannel>);
			m_channelFactory.registerClass("FormattingChannel", new TInstantiator<CFormattingChannel, CChannel>);
			m_channelFactory.registerClass("SplitterChannel", new TInstantiator<CSplitterChannel, CChannel>);
			m_channelFactory.registerClass("EventLogChannel", new TInstantiator<CEventLogChannel, CChannel>);
			

			m_formatterFactory.registerClass("PatternFormatter", new TInstantiator<CPatternFormatter, CFormatter>);
		}

	}//end of namespace log
}//end of namespace JHCPP
